package com.example.certificate.controller;


import com.example.certificate.service.WakeFileService;
import com.example.certificate.utils.ResultEntity;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * <p>
 * 文件上传 前端控制器
 * </p>
 *
 * @author HAO
 */
@RestController
@RequestMapping("/wakeFile")
public class WakeFileController {

    @Resource
    private WakeFileService wakeFileService;


    @PostMapping(value = "/uploadFile")
    @CrossOrigin
    @ApiOperation(value = "上传单文件(原图)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file",value = "MultipartFile上传文件",required = true,dataType = "MultipartFile"),
    })
    public ResultEntity uploadFile(@RequestParam MultipartFile file) throws Exception {
        return wakeFileService.uploadFile(file);
    }

    @GetMapping("/download")
    @ApiOperation(value = "下载单文件(原图)")
    public ResponseEntity<ByteArrayResource> download(@RequestParam String fileName) throws IOException {
        return wakeFileService.download(fileName);
    }
}

